/*
	生成20k个大小8k文件
	All Size is 160MB
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

char *
create_temp_name ()
{
	srand(time(NULL));
	char *name = (char *)malloc(5);
	char t;
	t = rand()%26 + 97;
	name[0] = t;
	t = rand()%26 + 97;
	name[1] = t;
	t = rand()%26 + 97;
	name[2] = t;
	t = rand()%26 + 97;
	name[3] = t;
	name[4] = '\0';

	return name;
}

int
main ()
{
	int i, j;							//20K counts of 8k file
	FILE *fp;
	char *name;
	char *str = (char *)malloc(1024);
	memset(str, '1', 1024);
	chdir("/home/jadsin/testdir/");
	for (i = 0; i < 20480; i++)
	{
		name = create_temp_name();
		while (access(name, F_OK) == 0)
		{
			free(name);
			name = create_temp_name();
		}
		fp = fopen(name, "w");
		for (j = 0; j < 8; j++)
		{
			fwrite(str, 1, 1024, fp);
		}
		fclose(fp);
		free(name);
	}
}